﻿<?php
require('../config.php');
require('tpl/auth/auth.php');
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>视频管理后台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="../dist/css/font-awesome-4.5.0/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="../plugins/ionicons-2.0.1/ionicons-2.0.1/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="../dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="../dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="../plugins/iCheck/flat/blue.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="../plugins/morris/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="../plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="../plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="../plugins/bootstrap-daterangepicker-master/daterangepicker.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
      <style>
          .wrapper{
              position: absolute;
              top: 0;
              width: 100%;
          }
          .videoImg{
              width: 100px;
              height:auto;
          }
          .videoUrl{
              width: 200px;
              height:200px;
          }
          .video-loading{
              display: none;
          }
          .loading{
              position: absolute;
              width:100%;
              height:100%;
              top:0;
              left: 0;
              background-color: rgba(255,255,255,0.8);
              z-index: 10;
              display: none;
          }
          .loading-center{
              position: absolute;
              margin: auto;
              top: 0;
              left: 0;
              right: 0;
              bottom: 0;
              width: 50px;
              height: 40px;
              z-index: 11;
          }
      </style>
  </head>
  <body class="hold-transition skin-blue sidebar-mini">
  <div class="loading">
      <i class="fa fa-spinner fa-pulse fa-3x fa-fw loading-center"></i>
      <span class="sr-only">Loading...</span>
  </div>

  <div class="wrapper">

      <?php require('tpl/common/nav.html');?>
      <?php if($_GET['p']=='dashboard'){
          require('tpl/dashboard/dashboard.html');}?>
      <?php if($_GET['p']=='video_add'){
          require('tpl/video/video_add.html');}?>
      <?php if($_GET['p']=='video_list'){
          require('tpl/video/video_list.html');}?>
      <?php if($_GET['p']=='ad_add'){
          require('tpl/ad/ad_add.html');}?>
      <?php if($_GET['p']=='ad_list'){
          require('tpl/ad/ad_list.html');}?>
      <?php if($_GET['p']=='category_add'){
          require('tpl/category/category_add.html');}?>
      <?php if($_GET['p']=='category_list'){
          require('tpl/category/category_list.html');}?>
  </div>
  <!--  <script src="../plugins/requirejs/require.js" data-main="js/config.js"></script>-->
  <!-- jQuery 2.1.4 -->
  <script src="../plugins/jQuery/jQuery-2.1.4.min.js"></script>
  <!-- Bootstrap 3.3.5 -->
  <script src="../plugins/bootstrap/js/bootstrap.min.js"></script>
  <!-- Morris.js charts -->
  <script src="../plugins/morris/morris.min.js"></script>
  <!-- Sparkline -->
  <script src="../plugins/sparkline/jquery.sparkline.min.js"></script>
  <!-- DataTables -->
  <script src="../plugins/knob/jquery.knob.js"></script>
  <!-- daterangepicker -->
  <script src="../plugins/bootstrap-daterangepicker-master/moment.js"></script>
  <script src="../plugins/bootstrap-daterangepicker-master/daterangepicker.js"></script>
  <!-- Bootstrap WYSIHTML5 -->
  <script src="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
  <!-- Slimscroll -->
  <script src="../plugins/slimScroll/jquery.slimscroll.min.js"></script>
  <!-- FastClick -->
  <script src="../plugins/fastclick/fastclick.min.js"></script>
  <!-- AdminLTE App -->
  <script src="../dist/js/app.min.js"></script>

  <script>


      $(document).ready(function () {
          init();
      });

      var page= 1,num=10;
      var host = "http://wx.miuiad.com";
      var category_id = '';
      var adtype = '';
      /**
       * 初始化函数集
       */
      function init(){
          initDomBind();

          uploadImg();
          uploadVideo();
          uploadFile();

          addVideo();
          getVideoList(category_id);

          addCategory();
          getCategoryList();

          addAd();
          getAdList();

          addAdType();
      }
      /**
       * 初始化dom绑定
       */
      function initDomBind(){
          $('#video-search').on('change',function(){
              category_id = $('#video-search').val();
              getVideoList(category_id);
          });
          $('#ad-search').on('change',function(){
              adtype = $('#ad-search').val();
              getAdList(adtype);
          });
          $('.pagination li:last a').on('click',function(){
              pageMani(1);
              getVideoList(category_id);

          });
          $('.pagination li:first a').on('click',function(){
              pageMani(0);
              getVideoList(category_id);
          });
          $('.category-pagination li:last a').on('click',function(){
              pageMani(1);
              getCategoryList();

          });
          $('.category-pagination li:first a').on('click',function(){
              pageMani(0);
              getCategoryList();
          });
          $('.ad-pagination li:last a').on('click',function(){
              pageMani(1);
              getAdList(adtype);

          });
          $('.ad-pagination li:first a').on('click',function(){
              pageMani(0);
              getAdList(adtype);
          });
          $('.ad-type-door').on('click',function(){
              $('.ad-type-model').fadeIn();
          });
          $('.ad-type-model-close').on('click',function(){
              $('.ad-type-model').fadeOut();
          });
          $('.ad-type-del').on('click', function(){
              var id = $(this).attr('title');
              deleteAdType(id);
          });
          $('.video-edit-model-close').on('click',function(){
              $('.video-edit-model').fadeOut();
          });
          $('.category-edit-model-close').on('click',function(){
              $('.category-edit-model').fadeOut();
          });
          $('.ad-edit-model-close').on('click',function(){
              $('.ad-edit-model').fadeOut();
          });
      }
      /**
       * 上传图片返回url
       */
      function uploadImg(){
          $('#imageUploadForm').on('submit',(function(e) {
              e.preventDefault();
              var formData = new FormData(this);
              loadingShow();
              $.ajax({
                  type:'POST',
                  url: $(this).attr('action'),
                  data:formData,
                  dataType: 'json',
                  cache:false,
                  contentType: false,
                  processData: false,
                  success:function(data){
                      loadingHide();

                      var imgUrl = data.info;
                      videoImg = $('.videoImg');
                      videoImg.attr("src",imgUrl);
                  },
                  error: function(data){
                      console.log("error");
                      console.log(data);
                  }
              });
          }));
          $("#ImageBrowse").on("change", function() {
              $("#imageUploadForm").submit();

          });
      }
      /**
       * 上传视频返回url
       */
      function uploadVideo(){

          $('#videoUploadForm').on('submit',(function(e) {
              e.preventDefault();
              $('.video-loading').fadeIn(100);
              var formData = new FormData(this);
              loadingShow();
              $.ajax({
                  type:'POST',
                  url: $(this).attr('action'),
                  data:formData,
                  dataType: 'json',
                  cache:false,
                  contentType: false,
                  processData: false,
                  success:function(data){
                      loadingHide();

                      $('.video-loading').fadeOut(100);
                      var video = data.info;
                      videoUrl = $('.videoUrl');
                      videoUrl.attr("src",video);


                  },
                  error: function(data){
                      console.log("error");
                      console.log(data);
                  }
              });
          }));

          $("#VideoBrowse").on("change", function() {
              $("#videoUploadForm").submit();
          });
      }
      /**
       * 上传文件返回url
       */
      function uploadFile(){

          $('#fileUploadForm').on('submit',(function(e) {
              e.preventDefault();
              $('.video-loading').fadeIn(100);
              var formData = new FormData(this);
              loadingShow();
              $.ajax({
                  type:'POST',
                  url: $(this).attr('action'),
                  data:formData,
                  dataType: 'json',
                  cache:false,
                  contentType: false,
                  processData: false,
                  success:function(data){
                      loadingHide();

                      $('.video-loading').fadeOut(100);
                      var url = data.info;
                      $('#fileUploadForm').append(url)


                  },
                  error: function(data){
                      console.log("error");
                      console.log(data);
                  }
              });
          }));

          $("#FileBrowse").on("change", function() {
              $("#fileUploadForm").submit();
          });
      }
      /**
       * 添加视频，类别，广告
       */
      function addVideo(){

              $('#addVideo').on('click', function() {
                  loadingShow();
                  var video_category_id = $('#video_category_id').val(),
                      video_title = $('#video_title').val(),
                      video_slogan = $('#video_slogan').val(),
                      video_detail = $('#video_detail').val(),
                      video_label = $('#video_label').val(),
                      //外链图片视频地址
                      video_img_outer_url = $('#video_img_outer_url').val(),
                      video_outer_url = $('#video_outer_url').val(),

                      video_video_url = video_outer_url!=''?video_outer_url:$('.videoUrl').attr('src'),
                      video_img_url = video_img_outer_url!=''?video_img_outer_url:$('.videoImg').attr('src');
                  $.ajax({
                      type: 'GET',
                      url: host + "/PhalApi/Public/xxkpcms/?service=Admin.AddVideo",
                      data: {
                          'category_id': video_category_id,
                          'img_url': video_img_url,
                          'title': video_title,
                          'slogan': video_slogan,
                          'detail': video_detail,
                          'video_url': video_video_url,
                          'label': video_label
                      },
                      dataType: 'json',
                      success: function (data) {
                          loadingHide();
                          if(data.code==1){
                              alert('添加成功');

                              reset("video_list");
                          }else{
                              alert(data.description);
                          }




                      },
                      error: function (data) {
                          console.log("error");
                          console.log(data);
                      },
                      always: function () {

                      }
                  });
              });
          $('#resetVideo').on('click', function(){
              reset("video_add");
          });
      }
      function addCategory(){

          $('#addCategory').on('click', function() {
              var category_name = $('#category_name').val(),
              //外链图片地址
                  category_img_outer_url = $('#category_img_outer_url').val(),
                  category_img = category_img_outer_url!=''?category_img_outer_url:$('.videoImg').attr('src');
              loadingShow();
              $.ajax({
                  type: 'GET',
                  url: host + "/PhalApi/Public/xxkpcms/?service=Admin.AddCategory",
                  data: {
                      'category_name': category_name,
                      'category_img': category_img,
                  },
                  dataType: 'json',
                  success: function (data) {
                      loadingHide();
                      if(data.info){
                          alert('添加成功');

                          reset("category_list")();
                      }else{
                          alert(data.description);
                      }




                  },
                  error: function (data) {
                      console.log("error");
                      console.log(data);
                  },
                  always: function () {

                  }
              });
          });
          $('#resetCategory').on('click', function(){
              reset("category_add");
          });
      }
      function addAd(){
          $('#addAd').on('click', function() {
              var ad_type = $('#ad_type').val(),
                  ad_title = $('#ad_title').val(),
                  ad_detail = $('#ad_detail').val(),
                  ad_url = $('#ad_url').val(),
              //外链图片地址
                  ad_img_outer_url = $('#ad_img_outer_url').val(),
                  ad_img = ad_img_outer_url!=''?ad_img_outer_url:$('.videoImg').attr('src');
              loadingShow();
              $.ajax({
                  type: 'GET',
                  url: host + "/PhalApi/Public/xxkpcms/?service=Admin.SetAd",
                  data: {
                      'type': ad_type,
                      'title': ad_title,
                      'detail': ad_detail,
                      'url': ad_url,
                      'img': ad_img
                  },
                  dataType: 'json',
                  success: function (data) {
                      loadingHide();
                      if(data.info){
                          alert('添加成功');

                          reset("ad_list");
                      }else{
                          alert(data.description);
                      }
                  },
                  error: function (data) {
                      console.log("error");
                      console.log(data);
                  },
                  always: function () {

                  }
              });
          });
          $('#resetAd').on('click', function(){
              reset("ad_add");
          });
      }
      function addAdType(){
          $('.addAdType').on('click', function() {
              var ad_type_name = $('#ad-type-name').val();
              loadingShow();
              $.ajax({
                  type: 'GET',
                  url: "apis/adType.php?action=add",
                  data: {
                      'name': ad_type_name
                  },
                  dataType: 'json',
                  success: function (data) {
                      loadingHide();
                      if(data==1){
                          alert('添加成功');

                          reset("ad_add");
                          setTimeout(function(){
                              $('.ad-type-model').fadeIn();
                          },0);
                      }else{
                          alert(data.description);
                      }
                  },
                  error: function (data) {
                      console.log("error");
                      console.log(data);
                  },
                  always: function () {

                  }
              });
          });
      }
      /**
       * 重置添加模块
       * @param model
       */
      function reset(model){
              window.location.href = host+"/admin_video/modules/index.php?p="+model;
      }
      /**
       * 获取视频，类别，广告列表
       * @param category_id
       */
      function getVideoList(category_id){
          loadingShow();

          $.ajax({
              type: 'GET',
              url: host + "/PhalApi/Public/xxkpcms/?service=Admin.GetVideoByCategoryId",
              data: {
                  'category_id': category_id?category_id:'',
                  'page': page,
                  'num': num
              },
              dataType: 'json',
              success: function (data) {
                  loadingHide();
                var videos = data.channelData;
                var count = data.count;
                var container;
                  for(var i in videos){
                       container += '<tr>'+
//                          '<td>'+videos[i].id+'</td>'+
//                          '<td>'+videos[i].category_id+'</td>'+
                          '<td>'+videos[i].title+'</td>'+
                          '<td><img class="videoImg" src='+videos[i].img_url+' title='+videos[i].img_url+'></td>'+
                          '<td>'+videos[i].slogan+'</td>'+
                          '<td>'+videos[i].detail+'</td>'+
                          '<td>'+(videos[i].video_url!=''?'<a target="_blank" href="'+videos[i].video_url+'" title="'+videos[i].video_url+'">查看</a>':'无')+'</td>'+
                          '<td>'+videos[i].label+'</td>'+
                          '<td>'+videos[i].time+'</td>'+
                          '<td>'+'<a><i class="fa fa-edit video-edit" title="'+videos[i].id+'"></i></a>&nbsp&nbsp|&nbsp&nbsp'+'<a><i class="fa fa-times video-del" title="'+videos[i].id+'"></i></a>'+'</td>';
                  }
                  $('#videoTable').html(count?container:'无数据');

                  $('.video-del').off('click').on('click' , function(){
                      var id = $(this).attr('title');
                      deleteVideo(id);
                  });
                  $('.video-edit').off('click').on('click',function(){
                      $('.video-edit-model').fadeIn();
                      var id = $(this).attr('title');
                      centerVideoDetails(id);
                  });
                  $('#video-num').html('总数：'+count+'条');

                  if(page==1&&count <= page * num){
                      console.log(1);
                      $('.video-pagination li:last a').removeClass('disabled').addClass('btn disabled');
                      $('.video-pagination li:first a').removeClass('disabled').addClass('btn disabled');
                  }else if(page==1&&count > page * num){
                      console.log(2);

                      $('.video-pagination li:last a').removeClass('disabled');
                      $('.video-pagination li:first a').removeClass('disabled').addClass('btn disabled');
                  }else if(page>1&&count <= page * num){
                      console.log(3);

                      $('.video-pagination li:last a').removeClass('disabled').addClass('btn disabled');
                      $('.video-pagination li:first a').removeClass('disabled');
                  }else if(page>1&&count > page * num){
                      console.log(4);

                      $('.video-pagination li:last a').removeClass('disabled');
                      $('.video-pagination li:first a').removeClass('disabled');
                  }else if(page<1){
                      pageMani();
                      $('.video-pagination li:last a').removeClass('disabled').addClass('btn');
                      $('.video-pagination li:first a').removeClass('disabled').addClass('btn disabled');
                  }

              },
              error: function (data) {
                  console.log("error");
                  console.log(data);
              }
          });
      }
      function getCategoryList(){
          loadingShow();

          $.ajax({
              type: 'GET',
              url: host + "/PhalApi/Public/xxkpcms/?service=Video.GetCategory",
              dataType: 'json',
              success: function (data) {
                  loadingHide();

                  var categorys = data.channel;
                var count = data.count;
                var container;
                  for(var i in categorys){
                       container += '<tr>'+
                          '<td>'+categorys[i].category_name+'</td>'+
                          '<td><img class="videoImg" src='+categorys[i].category_img+' title='+categorys[i].category_url+'></td>'+
                          '<td>'+'<a><i class="fa fa-edit category-edit" title="'+categorys[i].category_id+'"></i></a>&nbsp&nbsp|&nbsp&nbsp'+'<a href="#"><i class="fa fa-times category-del" title="'+categorys[i].category_id+'"></i></a>'+'</td>';
                  }
                  $('#categoryTable').html(container);

                  $('.category-edit').off('click').on('click',function(){
                      $('.category-edit-model').fadeIn();
                      var id = $(this).attr('title');
                      centerCategoryDetails(id);
                  });

                  $('.category-del').off('click').on('click' , function(){
                      var id = $(this).attr('title');
                      deleteCategory(id);
                  });

                  $('#category-num').html('总数：'+count+'条');

                  if(page==1&&count <= page * num){
                      $('.category-pagination li:last a').removeClass('disabled').addClass('btn disabled');
                      $('.category-pagination li:first a').removeClass('disabled').addClass('btn disabled');
                  }else if(page==1&&count > page * num){
                      $('.category-pagination li:last a').removeClass('disabled');
                      $('.category-pagination li:first a').removeClass('disabled').addClass('btn disabled');
                  }else if(page>1&&count <= page * num){
                      $('.category-pagination li:last a').removeClass('disabled').addClass('btn disabled');
                      $('.category-pagination li:first a').removeClass('disabled');
                  }else if(page>1&&count > page * num){
                      $('.category-pagination li:last a').removeClass('disabled');
                      $('.category-pagination li:first a').removeClass('disabled');
                  }else if(page<1){
                      pageMani();
                      $('.category-pagination li:last a').removeClass('disabled').addClass('btn');
                      $('.category-pagination li:first a').removeClass('disabled').addClass('btn disabled');
                  }

              },
              error: function (data) {
                  console.log("error");
                  console.log(data);
              }
          });
      }
      function getAdList(adtype){
          loadingShow();
          $.ajax({
              type: 'GET',
              url: host + "/PhalApi/Public/xxkpcms/?service=Ad.GetAd",
              data:{
                  'type': adtype?adtype:'',
                  'page': page,
                  'num': num
              },
              dataType: 'json',
              success: function (data) {
                  loadingHide();
                  var ads = data.ad;
                  var count = data.count;
                  var container;
                  for(var i in ads){
                      container += '<tr>'+
                          '<td>'+ads[i].type+'</td>'+
                          '<td>'+ads[i].title+'</td>'+
                          '<td>'+ads[i].detail+'</td>'+
                          '<td>'+ads[i].url+'</td>'+
                          '<td><img class="videoImg" src='+ads[i].img+' title='+ads[i].img+'></td>'+
                          '<td>'+'<a><i class="fa fa-edit ad-edit" title="'+ads[i].id+'"></i></a>&nbsp&nbsp|&nbsp&nbsp'+'<a href="#"><i class="fa fa-times ad-del" title="'+ads[i].id+'"></i></a>'+'</td>';
                  }
                  $('#adTable').html(container);

                  $('.ad-edit').off('click').on('click',function(){
                      $('.ad-edit-model').fadeIn();
                      var id = $(this).attr('title');
                      centerAdDetails(id);
                  });

                  $('.ad-del').off('click').on('click' , function(){
                      var id = $(this).attr('title');
                      deleteAd(id);
                  });

                  $('#ad-num').html('总数：'+count+'条');

                  if(page==1&&count <= page * num){
                      $('.ad-pagination li:last a').removeClass('disabled').addClass('btn disabled');
                      $('.ad-pagination li:first a').removeClass('disabled').addClass('btn disabled');
                  }else if(page==1&&count > page * num){
                      $('.ad-pagination li:last a').removeClass('disabled');
                      $('.ad-pagination li:first a').removeClass('disabled').addClass('btn disabled');
                  }else if(page>1&&count <= page * num){
                      $('.pagination li:last a').removeClass('disabled').addClass('btn disabled');
                      $('.pagination li:first a').removeClass('disabled');
                  }else if(page>1&&count > page * num){
                      $('.ad-pagination li:last a').removeClass('disabled');
                      $('.ad-pagination li:first a').removeClass('disabled');
                  }else if(page<1){
                      pageMani();
                      $('.ad-pagination li:last a').removeClass('disabled').addClass('btn');
                      $('.ad-pagination li:first a').removeClass('disabled').addClass('btn disabled');
                  }

              },
              error: function (data) {
                  console.log("error");
                  console.log(data);
              },
              always: function () {

              }
          });
      }

      /**
       * 视频更新
       */
      function centerVideoDetails(id) {
          loadingShow();
          $.ajax({
              type: 'GET',
              url: "apis/video.php",
              data: {
                  'id': id,
              },
              dataType: 'json',
              success: function (data) {
                  loadingHide();
                  $('#update_video_category_id').val(data.category_id);
                  $('#update_video_title').val(data.title);
                  $('#update_video_slogan').val(data.slogan);
                  $('#update_video_detail').val(data.detail);
                  $('#update_video_label').val(data.label);
                  $('#update_video_img_url').val(data.img_url);
                  $('#update_video_url').val(data.video_url);
                  updateVideoDetails(data.id);
              }
          });
      }
      function updateVideoDetails(id){

          $('.update-video').off('click').on('click', function() {
              var update_category_id = $('#update_video_category_id').val(),
                  title =$('#update_video_title').val(),
                  slogan =$('#update_video_slogan').val(),
                  detail =$('#update_video_detail').val(),
                  label =$('#update_video_label').val(),
                  img_url =$('#update_video_img_url').val(),
                  video_url =$('#update_video_url').val();
              loadingShow();
              $.ajax({
                  type: 'GET',
                  url: "apis/video.php?action=update",
                  data: {
                      'id': id,
                      'category_id': update_category_id,
                      'title': title,
                      'slogan': slogan,
                      'detail': detail,
                      'label': label,
                      'img_url': img_url,
                      'video_url': video_url
                  },
                  dataType: 'json',
                  success: function (data) {
                      loadingHide();
                      if(data==1){
                          alert('修改成功');
                          $('.video-edit-model').fadeOut();
                          getVideoList(category_id);

                      }else{
                          alert('更新失败');
                      }
                  },
                  error: function (data) {
                      console.log("error");
                      console.log(data);
                  },
                  always: function () {

                  }
              });
          });

      }
      /**
       * 类别更新
       */
      function centerCategoryDetails(id) {
          loadingShow();
          $.ajax({
              type: 'GET',
              url: "apis/category.php",
              data: {
                  'id': id
              },
              dataType: 'json',
              success: function (data) {
                  loadingHide();
                  $('#update_category_name').val(data.category_name);
                  $('#update_category_img').val(data.category_img);
                  updateCategoryDetails(data.category_id);
              }
          });
      }
      function updateCategoryDetails(id){

          $('.update-category').off('click').on('click', function() {
              var category_name =$('#update_category_name').val(),
                  category_img =$('#update_category_img').val();
              loadingShow();
              $.ajax({
                  type: 'GET',
                  url: "apis/category.php?action=update",
                  data: {
                      'category_id': id,
                      'category_name': category_name,
                      'category_img': category_img
                  },
                  dataType: 'json',
                  success: function (data) {
                      loadingHide();
                      if(data==1){
                          alert('修改成功');
                          $('.category-edit-model').fadeOut();
                          getCategoryList();

                      }else{
                          alert('更新失败');
                      }
                  },
                  error: function (data) {
                      console.log("error");
                      console.log(data);
                  },
                  always: function () {

                  }
              });
          });

      }
      /**
       *广告更新
       */
      function centerAdDetails(id) {
          loadingShow();
          $.ajax({
              type: 'GET',
              url: "apis/ad.php",
              data: {
                  'id': id
              },
              dataType: 'json',
              success: function (data) {
                  loadingHide();
                  $('#update_ad_type').val(data.type);
                  $('#update_ad_title').val(data.title);
                  $('#update_ad_detail').val(data.detail);
                  $('#update_ad_url').val(data.url);
                  $('#update_ad_img_url').val(data.img);
                  updateAdDetails(data.id);
              }
          });
      }
      function updateAdDetails(id) {

          $('.update-ad').off('click').on('click', function () {
              var type = $('#update_ad_type').val(),
                  title = $('#update_ad_title').val(),
                  detail = $('#update_ad_detail').val(),
                  url = $('#update_ad_url').val(),
                  img = $('#update_ad_img_url').val();
              loadingShow();
              $.ajax({
                  type: 'GET',
                  url: "apis/ad.php?action=update",
                  data: {
                      'id': id,
                      'type': type,
                      'title': title,
                      'detail': detail,
                      'url': url,
                      'img': img
                  },
                  dataType: 'json',
                  success: function (data) {
                      loadingHide();
                      if (data == 1) {
                          alert('修改成功');
                          $('.ad-edit-model').fadeOut();
                          getAdList(adtype);

                      } else {
                          alert('更新失败');
                      }
                  },
                  error: function (data) {
                      console.log("error");
                      console.log(data);
                  },
                  always: function () {

                  }
              });
          });
      }

          /**
       * 删除
       * @param id
       */
      function deleteVideo(id){
          var result = confirm('确认删除当前视频吗？');
          if(result==true){
              loadingShow();
              $.ajax({
                      url: 'apis/video.php?action=del',
                      type: 'GET',
                      dataType: 'json',
                      data: {
                          'id' : id
                      }
                  })
                  .done(function(data) {
                      loadingHide();
                      if(data==1){
                          alert('删除成功');
                          getVideoList(category_id);
                      }else{
                          alert('缺失参数');
                      }
                  })
                  .fail(function() {
                      console.log("error");
                  })
          }
      }
      function deleteCategory(id){
          var result = confirm('确认删除当前类别吗？');
          if(result==true){
              loadingShow();
              $.ajax({
                      url: 'apis/category.php?action=del',
                      type: 'GET',
                      dataType: 'json',
                      data: {
                          'id' : id,
                      },
                  })
                  .done(function(data) {
                      loadingHide();
                      if(data==1){
                          alert('删除成功');
                          getCategoryList();
                      }else{
                          alert('缺失参数');
                      }
                  })
                  .fail(function() {
                      console.log("error");
                  })
                  .always(function() {
                  });
          }
      }
      function deleteAd(id){
          var result = confirm('确认删除当前类别吗？');
          if(result==true){
              loadingShow();
              $.ajax({
                      url: 'apis/ad.php?action=del',
                      type: 'GET',
                      dataType: 'json',
                      data: {
                          'id' : id,
                      },
                  })
                  .done(function(data) {
                      loadingHide();

                      if(data==1){
                          alert('删除成功');
                          getAdList();
                      }else{
                          alert('缺失参数');
                      }
                  })
                  .fail(function() {
                      console.log("error");
                  })
                  .always(function() {
                  });
          }
      }
      function deleteAdType(id){
          var result = confirm('确认删除当前类别吗？');
          if(result==true){
              loadingShow();
              $.ajax({
                      url: 'apis/adType.php?action=del',
                      type: 'GET',
                      dataType: 'json',
                      data: {
                          'id' : id
                      },
                  })
                  .done(function(data) {
                      loadingHide();
                      if(data==1){
                          alert('删除成功');
                          reset('ad_add');
                          setTimeout(function(){
                              $('.ad-type-model').fadeIn();
                          },0)
                      }else{
                          alert('缺失参数');
                      }
                  })
                  .fail(function() {
                      console.log("error");
                  })
                  .always(function() {
                  });
          }
      }

      function pageMani(action){
          if(action == 0){
              page--;
          }else if( action == 1 ){
              page++;
          }else{
              page=1;
          }
          $('#page-current').html(page);
      }

      function loadingShow(){
          $('.loading').fadeIn()
      }
      function loadingHide(){
          $('.loading').fadeOut()
      }
  </script>
  </body>
  <script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1257484594'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s11.cnzz.com/z_stat.php%3Fid%3D1257484594' type='text/javascript'%3E%3C/script%3E"));</script>
</html>
